package com.wannengbang.storemobile.mine;

import android.os.Bundle;
import android.view.View;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ProgressBar;

import com.wannengbang.storemobile.R;
import com.wannengbang.storemobile.base.BaseActivity;
import com.wannengbang.storemobile.widget.AppTitleBar;
import com.wannengbang.storemobile.widget.LollipopFixedWebView;

import butterknife.BindView;
import butterknife.ButterKnife;

public class UserAgreementActivity extends BaseActivity {

    @BindView(R.id.title_bar)
    AppTitleBar titleBar;
    @BindView(R.id.webView)
    LollipopFixedWebView webView;
    @BindView(R.id.progressBar)
    ProgressBar progressBar;
    //服务协议1  隐私政策2
    private int type = 1;
    private String url;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_user_agreement);
        ButterKnife.bind(this);
        type = getIntent().getIntExtra("type", 1);
        url = getIntent().getStringExtra("url");
        initView();
    }

    public void initView() {
        webView.setWebViewClient(new WebViewClient() {
            //覆写shouldOverrideUrlLoading实现内部显示网页
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                view.loadUrl(url);
                return true;
            }
        });
        webView.setWebChromeClient(new WebChromeClient() {
            @Override
            public void onProgressChanged(WebView view, int newProgress) {
                if (newProgress == 100) {
                    progressBar.setVisibility(View.GONE);//加载完网页进度条消失
                } else {
                    progressBar.setVisibility(View.VISIBLE);//开始加载网页时显示进度条
                    progressBar.setProgress(newProgress);//设置进度值
                }

            }
        });
        WebSettings webSettings = webView.getSettings();//Dom Storage（Web Storage）存储机制
        webSettings.setDomStorageEnabled(true);
        webSettings.setBlockNetworkImage(true);
        webSettings.setJavaScriptEnabled(true);
        webSettings.setBlockNetworkImage(false);//解决图片不显示
        webSettings.setCacheMode(WebSettings.LOAD_NO_CACHE);
        if (type == 1) {
            titleBar.setTitle("服务协议");
            webView.loadUrl("https://dc.zhengzhouwannengbang.com/index.php/index/Page/serviceAgreement");
        } else if (type == 2) {
            titleBar.setTitle("隐私政策");
            webView.loadUrl("https://dc.zhengzhouwannengbang.com/index.php/index/Page/yinsixieyi2");
        } else if (type == 3) {
            titleBar.setTitle("提现协议");
            webView.loadUrl("https://dc.zhengzhouwannengbang.com/index.php/index/Spa/agent/oem_no/wannengbang#/agent_apply_with_draw_text");
        } else if (type == 4) {
            titleBar.setTitle("共享经济合作伙伴协议");
            webView.loadUrl("https://dc.zhengzhouwannengbang.com/index.php/index/Page/yunzhanghuxieyi");
        }else if (type == 5) {
            titleBar.setTitle("签约");
            webView.loadUrl(url);
        }
    }
}
